/*     */ package com.wgcloud.controller;
/*     */ 
/*     */ import cn.hutool.json.JSONObject;
/*     */ import cn.hutool.json.JSONUtil;
/*     */ import com.github.pagehelper.PageInfo;
/*     */ import com.wgcloud.entity.AppInfo;
/*     */ import com.wgcloud.entity.AppState;
/*     */ import com.wgcloud.entity.SystemInfo;
/*     */ import com.wgcloud.service.AppInfoService;
/*     */ import com.wgcloud.service.AppStateService;
/*     */ import com.wgcloud.service.DashboardService;
/*     */ import com.wgcloud.service.ExcelExportService;
/*     */ import com.wgcloud.service.HostGroupService;
/*     */ import com.wgcloud.service.LogInfoService;
/*     */ import com.wgcloud.service.SystemInfoService;
/*     */ import com.wgcloud.util.DateUtil;
/*     */ import com.wgcloud.util.FormatUtil;
/*     */ import com.wgcloud.util.HostUtil;
/*     */ import com.wgcloud.util.PageUtil;
/*     */ import com.wgcloud.util.ResDataUtils;
/*     */ import com.wgcloud.util.TokenUtils;
/*     */ import com.wgcloud.util.license.LicenseUtil;
/*     */ import com.wgcloud.util.staticvar.StaticKeys;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.annotation.Resource;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.Model;
/*     */ import org.springframework.web.bind.annotation.RequestBody;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/appInfo"})
/*     */ public class AppInfoController {
/*  44 */   private static final Logger logger = LoggerFactory.getLogger(com.wgcloud.controller.AppInfoController.class);
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private AppInfoService appInfoService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private AppStateService appStateService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private LogInfoService logInfoService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private DashboardService dashBoardService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private SystemInfoService systemInfoService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private HostGroupService hostInfoService;
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private DashboardService dashboardService;
/*     */   
/*     */   @Resource
/*     */   private ExcelExportService excelExportService;
/*     */   
/*     */   @Autowired
/*     */   private TokenUtils tokenUtils;
/*     */ 
/*     */   
/*     */   @ResponseBody
/*     */   @RequestMapping({"agentList"})
/*     */   public String agentList(@RequestBody String paramBean) {
/*  84 */     JSONObject agentJsonObject = (JSONObject)JSONUtil.parse(paramBean);
/*  85 */     if (!this.tokenUtils.checkAgentToken(agentJsonObject)) {
/*  86 */       logger.error("token is error");
/*  87 */       return ResDataUtils.resetErrorJson("token is error");
/*     */     } 
/*  89 */     Map<String, Object> params = new HashMap<>();
/*  90 */     if (null == agentJsonObject.get("hostname") || StringUtils.isEmpty(agentJsonObject.get("hostname").toString())) {
/*  91 */       return "";
/*     */     }
/*  93 */     params.put("hostname", agentJsonObject.get("hostname").toString());
/*     */     try {
/*  95 */       params.put("active", "1");
/*  96 */       List<AppInfo> appInfoList = this.appInfoService.selectAllByParams(params);
/*  97 */       return ResDataUtils.resetSuccessJson(appInfoList);
/*  98 */     } catch (Exception e) {
/*  99 */       logger.error("agent获取进程信息错误", e);
/* 100 */       this.logInfoService.save("agent获取进程信息错误", e.toString(), "1");
/* 101 */       return ResDataUtils.resetErrorJson(e.toString());
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"list"})
/*     */   public String AppInfoList(AppInfo appInfo, Model model, HttpServletRequest request) {
/* 114 */     Map<String, Object> params = new HashMap<>();
/*     */     
/*     */     try {
/* 117 */       LicenseUtil.maxLicense_10(model, request);
/*     */ 
/*     */       
/* 120 */       StringBuffer url = new StringBuffer();
/* 121 */       String hostname = null;
/* 122 */       if (!StringUtils.isEmpty(appInfo.getHostname())) {
/* 123 */         hostname = appInfo.getHostname();
/* 124 */         params.put("hostname", hostname.trim());
/* 125 */         url.append("&hostname=").append(hostname);
/*     */       } 
/* 127 */       if (!StringUtils.isEmpty(appInfo.getOrderBy())) {
/* 128 */         params.put("orderBy", appInfo.getOrderBy());
/* 129 */         params.put("orderType", appInfo.getOrderType());
/* 130 */         url.append("&orderBy=").append(appInfo.getOrderBy());
/* 131 */         url.append("&orderType=").append(appInfo.getOrderType());
/*     */       } 
/* 133 */       if (!StringUtils.isEmpty(appInfo.getState())) {
/* 134 */         params.put("state", appInfo.getState());
/* 135 */         url.append("&state=").append(appInfo.getState());
/*     */       } 
/* 137 */       PageInfo<AppInfo> pageInfo = this.appInfoService.selectByParams(params, appInfo.getPage().intValue(), appInfo.getPageSize().intValue());
/* 138 */       for (AppInfo appInfo1 : pageInfo.getList()) {
/* 139 */         appInfo1.setWritesBytes(FormatUtil.mToG(appInfo1.getWritesBytes()));
/* 140 */         appInfo1.setReadBytes(FormatUtil.mToG(appInfo1.getReadBytes()));
/* 141 */         appInfo1.setHostname(appInfo1.getHostname() + HostUtil.addRemark(appInfo1.getHostname()));
/*     */       } 
/* 143 */       PageUtil.initPageNumber(pageInfo, model);
/* 144 */       model.addAttribute("pageUrl", "/appInfo/list?1=1" + url.toString());
/* 145 */       model.addAttribute("page", pageInfo);
/* 146 */       model.addAttribute("appInfo", appInfo);
/* 147 */     } catch (Exception e) {
/* 148 */       logger.error("查询进程信息错误", e);
/* 149 */       this.logInfoService.save("查询进程信息错误", e.toString(), "1");
/*     */     } 
/*     */     
/* 152 */     return "app/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"save"})
/*     */   public String saveAppInfo(AppInfo appInfo, Model model, HttpServletRequest request) {
/* 166 */     String errorMsg = "保存进程错误";
/*     */     try {
/* 168 */       if (StringUtils.isEmpty(appInfo.getId())) {
/* 169 */         this.appInfoService.save(appInfo);
/*     */       } else {
/* 171 */         this.appInfoService.updateById(appInfo);
/*     */       } 
/* 173 */     } catch (Exception e) {
/* 174 */       logger.error(errorMsg, e);
/* 175 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 177 */     return "redirect:/appInfo/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"saveBatch"})
/*     */   public String saveBatchAppInfo(AppInfo appInfo, Model model, HttpServletRequest request) {
/* 190 */     String errorMsg = "批量保存进程错误";
/*     */     try {
/* 192 */       String[] hostnames = request.getParameterValues("hostnames");
/* 193 */       if (null == hostnames || hostnames.length < 1) {
/* 194 */         return "redirect:/appInfo/list";
/*     */       }
/* 196 */       for (String selectedHost : hostnames) {
/* 197 */         appInfo.setHostname(selectedHost);
/* 198 */         this.appInfoService.save(appInfo);
/*     */       } 
/* 200 */     } catch (Exception e) {
/* 201 */       logger.error(errorMsg, e);
/* 202 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 204 */     return "redirect:/appInfo/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"edit"})
/*     */   public String edit(Model model, HttpServletRequest request) {
/* 216 */     String errorMsg = "添加进程错误";
/* 217 */     String id = request.getParameter("id");
/* 218 */     AppInfo appInfo = new AppInfo();
/*     */     try {
/* 220 */       List<SystemInfo> systemInfoList = this.systemInfoService.selectAllByParams(new HashMap<>());
/* 221 */       model.addAttribute("systemInfoList", systemInfoList);
/* 222 */       if (StringUtils.isEmpty(id)) {
/* 223 */         model.addAttribute("appInfo", appInfo);
/*     */         
/* 225 */         Map<String, Object> params = new HashMap<>();
/* 226 */         int dbSize = this.appInfoService.countByParams(params);
/* 227 */         if (dbSize >= 10 && !StaticKeys.LICENSE_STATE.equals("1")) {
/* 228 */           return "redirect:/appInfo/list?liceFlage=1";
/*     */         }
/*     */         
/* 231 */         return "app/add";
/*     */       } 
/* 233 */       appInfo = this.appInfoService.selectById(id);
/* 234 */       model.addAttribute("appInfo", appInfo);
/* 235 */     } catch (Exception e) {
/* 236 */       logger.error(errorMsg, e);
/* 237 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 239 */     return "app/add";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"editBatch"})
/*     */   public String editBatch(Model model, HttpServletRequest request) {
/* 251 */     String errorMsg = "批量添加进程错误";
/* 252 */     AppInfo appInfo = new AppInfo();
/*     */     try {
/* 254 */       List<SystemInfo> systemInfoList = this.systemInfoService.selectAllByParams(new HashMap<>());
/* 255 */       model.addAttribute("systemInfoList", systemInfoList);
/* 256 */       model.addAttribute("appInfo", appInfo);
/*     */       
/* 258 */       Map<String, Object> params = new HashMap<>();
/* 259 */       int dbSize = this.appInfoService.countByParams(params);
/* 260 */       if (dbSize >= 10 && !StaticKeys.LICENSE_STATE.equals("1")) {
/* 261 */         return "redirect:/appInfo/list?liceFlage=1";
/*     */       }
/*     */     }
/* 264 */     catch (Exception e) {
/* 265 */       logger.error(errorMsg, e);
/* 266 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 268 */     return "app/addBatch";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"view"})
/*     */   public String viewChart(Model model, HttpServletRequest request) {
/* 282 */     String errorMsg = "查看进程统计图错误";
/* 283 */     String id = request.getParameter("id");
/* 284 */     String date = request.getParameter("date");
/* 285 */     String am = request.getParameter("am");
/* 286 */     AppInfo appInfo = new AppInfo();
/*     */     try {
/* 288 */       appInfo = this.appInfoService.selectById(id);
/* 289 */       Map<String, Object> params = new HashMap<>();
/* 290 */       if (StringUtils.isEmpty(date)) {
/* 291 */         date = DateUtil.getCurrentDate();
/* 292 */         am = this.dashboardService.getDefaultAm();
/*     */       } 
/* 294 */       this.dashboardService.setDateParam(am, date, params);
/* 295 */       model.addAttribute("am", am);
/* 296 */       model.addAttribute("datenow", date);
/* 297 */       model.addAttribute("dateList", this.dashboardService.getDateList());
/* 298 */       model.addAttribute("amList", this.dashboardService.getAmList());
/* 299 */       params.put("appInfoId", appInfo.getId());
/* 300 */       model.addAttribute("appInfo", appInfo);
/* 301 */       List<AppState> appStateList = this.appStateService.selectAllByParams(params);
/* 302 */       model.addAttribute("appStateList", JSONUtil.parseArray(appStateList));
/* 303 */     } catch (Exception e) {
/* 304 */       logger.error(errorMsg, e);
/* 305 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 307 */     return "app/view";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"chartExcel"})
/*     */   public void chartExcel(Model model, HttpServletRequest request, HttpServletResponse response) {
/* 320 */     String errorMsg = "进程统计图导出excel错误";
/* 321 */     String id = request.getParameter("id");
/* 322 */     String date = request.getParameter("date");
/* 323 */     String am = request.getParameter("am");
/*     */     try {
/* 325 */       if (!StaticKeys.LICENSE_STATE.equals("1")) {
/* 326 */         response.setContentType("text/html;charset=UTF-8");
/* 327 */         response.getOutputStream().write("The excel needs to wgcloud-pro version".getBytes());
/*     */         return;
/*     */       } 
/* 330 */       if (StringUtils.isEmpty(id)) {
/* 331 */         response.setContentType("text/html;charset=UTF-8");
/* 332 */         response.getOutputStream().write("The excel must  require parameters".getBytes());
/*     */         return;
/*     */       } 
/* 335 */       Map<String, Object> params = new HashMap<>();
/* 336 */       if (StringUtils.isEmpty(date)) {
/* 337 */         date = DateUtil.getCurrentDate();
/* 338 */         am = this.dashboardService.getDefaultAm();
/*     */       } 
/* 340 */       params.put("appInfoId", id);
/* 341 */       this.dashboardService.setDateParam(am, date, params);
/* 342 */       this.excelExportService.exportAppExcel(params, response);
/* 343 */     } catch (Exception e) {
/* 344 */       logger.error(errorMsg, e);
/* 345 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"del"})
/*     */   public String delete(Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) {
/* 360 */     String errorMsg = "删除进程信息错误";
/* 361 */     AppInfo appInfo = new AppInfo();
/*     */     try {
/* 363 */       if (!StringUtils.isEmpty(request.getParameter("id"))) {
/* 364 */         String[] ids = request.getParameter("id").split(",");
/* 365 */         for (String id : ids) {
/* 366 */           appInfo = this.appInfoService.selectById(id);
/* 367 */           this.logInfoService.save("删除进程：" + appInfo.getHostname(), "删除进程：" + appInfo.getHostname() + "：" + appInfo.getAppPid(), "0");
/*     */         } 
/* 369 */         this.appInfoService.deleteById(request.getParameter("id").split(","));
/*     */       } 
/* 371 */     } catch (Exception e) {
/* 372 */       logger.error(errorMsg, e);
/* 373 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/* 375 */     return "redirect:/appInfo/list";
/*     */   }
/*     */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/controller/AppInfoController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */